#include <map>

class Solution
{
public:
    vector<int> twoSum(vector<int> &nums, int target)
    {
        map<int, int> comp;
        for (int i = 0; i < nums.size(); ++i)
        {
            comp.insert_or_assign(target - nums[i], i);
        }
        for (int i = 0; i < nums.size(); ++i)
        {
            if (comp.find(nums[i]) != comp.end())
            {
                if (comp[nums[i]] == i)
                    continue;
                return vector<int>{comp[nums[i]], i};
            }
        }
        return vector<int>();
    }
};
